<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        Array.prototype.myMap = function (cb) {
            if (typeof this != "object") {
                throw TypeError(this+"type err");
            }
            if (typeof cb != "function" || cb === null) {
                throw TypeError(cb + "type err");
            }
            const result = [];
            for(let i = 0;i<this.length;i++)
            {
                result.push(cb(this[i],i,this));
            }
            return result;
        }

        let arr = [1,2,3,4];
        let result = arr.myMap((item)=>{return item*item});
        console.log(result);
    </script>
</body>

</html>